﻿Imports System.Resources
Imports System.Threading
Imports Biz
Imports BLL



Public Class ctrlPoliticasSeguridad
    Private _llamador As frmMainMetro
    Private _oPoliticasSeguridad As cPoliticas_Seguridad
    Private _RM As ResourceManager


    Public Sub SetIdioma()

        _RM = New ResourceManager("UI.Idiomas", System.Reflection.Assembly.GetExecutingAssembly)

        btnAceptar.Text = _RM.GetString("btnAceptar")
        btnCancelar.Text = _RM.GetString("btnCancelar")

    End Sub

    Public Property Llamador() As frmMainMetro
        Get
            Return _llamador
        End Get
        Set(value As frmMainMetro)
            _llamador = value
        End Set
    End Property

    Private Function ValidarForm() As Boolean
        Dim bValido As Boolean = True
        Dim oAux As cPassword = New cPassword


        If txtCantMinimaCaract.Text.Trim = "" Then bValido = False
        If txtCantMaximaCaract.Text.Trim = "" Then bValido = False
        If txtCantDiasDuracion.Text.Trim = "" Then bValido = False

        If Utils.Convert.ToInt16(txtCantMinimaCaract.Text) < 0 Then bValido = False
        If Utils.Convert.ToInt16(txtCantMaximaCaract.Text) < 0 Then bValido = False
        If Utils.Convert.ToInt16(txtCantDiasDuracion.Text) < 0 Then bValido = False

        If bValido = False Then
            lblMensajes.Text = "Complete todos los datos requeridos..."
        End If

        If Utils.Convert.ToInt16(txtCantMinimaCaract.Text) >= Utils.Convert.ToInt16(txtCantMaximaCaract.Text) Then
            bValido = False
            lblMensajes.Text = "La cantidad mínima de caracteres debe ser menor a la cantidad máxima"
        End If

        ValidarForm = bValido

    End Function

    Private Sub txtCantMinimaCaract_KeyPress(sender As Object, e As KeyPressEventArgs)
        e.Handled = Not IsNumeric(e.KeyChar) And Not Char.IsControl(e.KeyChar)
    End Sub

    Private Sub txtCantMaximaCaract_KeyPress(sender As Object, e As KeyPressEventArgs)
        e.Handled = Not IsNumeric(e.KeyChar) And Not Char.IsControl(e.KeyChar)
    End Sub

    Private Sub txtCantDiasDuracion_KeyPress(sender As Object, e As KeyPressEventArgs)
        e.Handled = Not IsNumeric(e.KeyChar) And Not Char.IsControl(e.KeyChar)
    End Sub

    Public Sub MostrarParaEdicion()

        lblTituloForm.Text = "Políticas de contraseña"
        lblMensajes.Text = ""

        Try
            _oPoliticasSeguridad = GestorPoliticas_Seguridad.Instance.Buscar()
        Catch ex As Exception
            Main.ManejarExcepcion(ex)
        End Try

        LlenarForm(_oPoliticasSeguridad)

        txtCantMinimaCaract.Focus()

    End Sub

    Private Sub LlenarForm(oAux As cPoliticas_Seguridad)

        If Not oAux Is Nothing Then
            txtCantMinimaCaract.Text = oAux.Pwd_Char_Min
            txtCantMaximaCaract.Text = oAux.Pwd_Char_Max
            txtCantDiasDuracion.Text = oAux.Pwd_Duracion
        Else
            txtCantMinimaCaract.Text = ""
            txtCantMaximaCaract.Text = ""
            txtCantDiasDuracion.Text = ""
        End If


    End Sub

    Private Sub txtCantMinimaCaract_KeyPress1(sender As Object, e As KeyPressEventArgs) Handles txtCantMinimaCaract.KeyPress
        e.Handled = Not IsNumeric(e.KeyChar) And Not Char.IsControl(e.KeyChar)
    End Sub

    Private Sub txtCantMaximaCaract_KeyPress1(sender As Object, e As KeyPressEventArgs) Handles txtCantMaximaCaract.KeyPress
        e.Handled = Not IsNumeric(e.KeyChar) And Not Char.IsControl(e.KeyChar)
    End Sub

    Private Sub txtCantDiasDuracion_KeyPress1(sender As Object, e As KeyPressEventArgs) Handles txtCantDiasDuracion.KeyPress
        e.Handled = Not IsNumeric(e.KeyChar) And Not Char.IsControl(e.KeyChar)
    End Sub

    Private Sub btnAceptar_Click(sender As Object, e As EventArgs) Handles btnAceptar.Click
        Dim oAux As cPoliticas_Seguridad


        If ValidarForm() Then
            oAux = New cPoliticas_Seguridad
            oAux.Pwd_Char_Min = txtCantMinimaCaract.Text.Trim
            oAux.Pwd_Char_Max = txtCantMaximaCaract.Text.Trim
            oAux.Pwd_Duracion = txtCantDiasDuracion.Text.Trim

            Try
                GestorPoliticas_Seguridad.Instance.Editar(oAux)
            Catch ex As Exception
                Main.ManejarExcepcion(ex)
            End Try

            _llamador.CloseModalPanel(Me, DevComponents.DotNetBar.Controls.eSlideSide.Left)
            _llamador.RefrescarGrillas()
        End If

    End Sub

    Private Sub btnCancelar_Click(sender As Object, e As EventArgs) Handles btnCancelar.Click
        _llamador.CloseModalPanel(Me, DevComponents.DotNetBar.Controls.eSlideSide.Left)
    End Sub
End Class
